package com.idbk.chargestation.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;

import com.idbk.chargestation.R;
import com.idbk.chargestation.bll.PointFilter;
import com.idbk.chargestation.bll.PointFilter.PointFilterModel;

/**
 * 充电点过滤器
 *
 * @author lupc
 */
public class DialogPointFilter extends Dialog {

    public PointFilter mFilter;

    public DialogPointFilter(Context context, PointFilterModel model) {
        super(context);

        mFilter = new PointFilter(getContext(), model);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //隐藏标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        View view = getLayoutInflater().inflate(R.layout.dialog_point_filter, new RelativeLayout(getContext()), false);
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        mFilter.initView(view);
        setContentView(view);

        if (getWindow() != null) {
            getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        }

        //获取屏幕尺寸
        WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        Point point = new Point();
        display.getSize(point);
        //将dialog适配成固定尺寸
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
        Window window = getWindow();
        lp.copyFrom(window.getAttributes());
        //This makes the dialog take up the full width
        lp.width = Float.valueOf(point.x * 0.9f).intValue();
        lp.height = Float.valueOf(point.y * 0.8f).intValue();
        window.setAttributes(lp);

        //getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    }

}



